<template>
    <div>
        <div class="mg-content">

          <div class="" style="padding-bottom:20px;text-align: left;">
            <el-button v-hasPermission="'management_syncStock:create'" class="title-button btn-primary" size="medium" @click="addFindShow=true;activityId=''" icon="el-icon-plus">批量下发&nbsp;</el-button>
          </div>
                <el-table
                     v-loading="loading"
                     :data="tableData"
                     :border="true"
                     style="width: 100%">
                    <el-table-column
                       type="index"
                       width="50">
                     </el-table-column>
                    <el-table-column
                            label="门店名称">
                        <template  slot-scope="scope">
                            <span>{{scope.row.name}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                            label="上次下发时间">
                        <template  slot-scope="scope">
                            <span>{{scope.row.lastTime}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                            label="最新下发时间"
                            prop="thisTime"
                    >
                    </el-table-column>
                    <el-table-column
                            label="状态">
                        <template  slot-scope="scope">
                            <span v-if="scope.row.state">{{scope.row.state.text}}</span>
                        </template>
                    </el-table-column>
                     <!--<el-table-column-->
                             <!--label="查看" width="70">-->
                         <!--<template  slot-scope="scope">-->
                             <!--<router-link :to="'/warehouses/stores/show?id='+scope.row.id">-->
                                 <!--<span class="icon icon-chakanmingxi table-icon"></span>-->
                             <!--</router-link>-->
                         <!--</template>-->
                     <!--</el-table-column>-->
                  <el-table-column
                    label="操作" width="200">
                    <template scope="scope" >
                      <!--<el-button type="text" size="small" style="margin: 0px;" @click=""  >启用</el-button>-->
                      <el-button :disabled="canSave" v-hasPermission="'management_syncStock:create'" type="text" size="small" style="margin: 0px;" @click="goCommit(scope.row)" >重新下发 | </el-button>
                     <!-- <el-button :disabled="canSave"  v-hasPermission="'management_syncStock:create'" type="text" size="small" @click="goCommit(scope.row)">
                        <span v-if="canSave"><i class="el-icon-loading"></i>正在下发 | </span>
                        <span v-else>重新下发 | </span>
                      </el-button>-->


                      <el-button @click="addShow=true;activityId=scope.row.id" type="text" style="margin: 0px;" size="small">查看</el-button>
                    </template>
                  </el-table-column>
                </el-table>
            <br>
            <div class="block">
                <el-row>
                    <el-col :span="24" class="text-right">
                       <el-pagination
                           @size-change="handleSizeChange"
                           @current-change="handleCurrentChange"
                           :current-page="currentPage"
                           :page-sizes="pageSizes"
                           :page-size="pageSize"
                           layout="total, sizes, prev, pager, next, jumper"
                           :total="total">
                       </el-pagination>
                    </el-col>
                </el-row>
            </div>
        </div>
        <model :isShow="addShow" :id="activityId" @close="addClose" @addSuccess="addSuccess"></model>
      <set-store  :isShow="addFindShow" :id="activityId" @close="addClose1" @addSuccess="addSuccess1"></set-store>
        <PluginConfirm
                :show="dialogIsShow"
                @chooseSure="chooseSure()"
                @chooseCancel="chooseCancel()"
                @dialogResult="dialogResult">
        </PluginConfirm>
      <div v-if="canSave" class="is_lodding">
        <i class="el-icon-loading"></i>
        <div>正在下发中</div>
      </div>

    </div>

</template>
<script>
    //注意路径
    import model from './model.vue'
    import setStore from './setStore.vue'
    export default{
        data(){
            return {
              canSave:false,
                addFindShow:false,
                loading:false,
                tableData: [],
                pageSizes:window.pageSizes,//所有可选择的条数
                pageSize:window.pageSize,//控制一页显示的条数
                total:10,//总条数
                input:"",
                currentPage:1,
                inputValue:"",
                dialogIsShow:false,
                addShow:false,
                activityId:"",
                dialogIsShow:false,
                curDataRow:null,
                curDataIndex:0,
                selectItmeIndex:"",
                selectItemDetailsIndex:"",
                selectDelId:""

            }
        },
        components: {
           model,
          setStore
        },
        created(){
            window.this = this;
            this.initData();
        },
        methods: {
          goCommit(item){
            var data={};
            var branchs=[];
            branchs.push(item.branchId)
            data.branchs=branchs;
            if(this.canSave){

              return;
            }
            this.canSave = true;
            this.$axios
              .post("branchstores/syncStocks/create",data,"json")
              .then(data => {
                if (data.status == 200) {
                  this.$message({
                    message: data.message,
                    type: "success"
                  });
                  this.initData();
                  this.canSave = false;
                } else {
                  this.canSave = false;
                  this.$message.error(data.message);
                }
              });
          },
            initData(){
                this.currentPage=1;
                this.getData();
            },
            keyDown(ev){
                if(ev.keyCode==13) {
                    this.currentPage=1;
                    this.inputValue=this.input;
                    this.getData();
                }
            },
            cleanSearch(){
                this.currentPage=1;
                this.input="";
                this.inputValue=this.input;
                this.getData();
            },
            search(){
                this.currentPage=1;
                this.inputValue=this.input;
                this.getData();
            },
            handleCurrentChange(currentPage){
                this.currentPage=currentPage;
                this.getData();
            },
            getData(){
                this.loading=true;
                this.$axios.get("branchstores/syncStocks?page.pn="+this.currentPage+"&page.size="+this.pageSize+"&search.name_like,no_like="+this.inputValue).then((data)=>{
                    this.loading=false
                    this.tableData=data.content.content;
                    this.total=data.content.totalElements
                }).catch(function(err){
                 })
            },
            handleDelete(index,delIndex,id) {
                this.selectItmeIndex=index,
                this.selectItemDetailsIndex=delIndex;
                this.selectDelId=id;
                this.dialogIsShow=true;
            },
             dialogResult(param){
                this.dialogIsShow=param.close;
                if(param.choose==="ok"){
                    //console.log("确定");
                    this.$axios.delete("branchstores/branchWarehouses/"+this.selectDelId).then(data=>{
                        if(data.status==200){
                            this.tableData.splice(this.curDataIndex,1);
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.initData();
                        }else{
                            this.$message({
                                type: 'error',
                                message: data.message
                            });
                        }
                    })
                }else if(param.choose==="cancel"){
                    //console.log("取消");
                }else{
                    //console.log("不做处理");
                }
            },
            addSuccess(item){
                this.addShow=false;
                this.initData();
            },
            addClose(){
                this.addShow=false;
            },
          addSuccess1(item){
            this.addFindShow=false;
            this.initData();
          },
          addClose1(){
            this.addFindShow=false;
          },
            handleSizeChange(val){
                this.pageSize=val;
                this.getData();
            },
        }
    }
</script>
<style scoped>
  .is_lodding{
    position: absolute;
    z-index: 2000;
    background-color: hsla(0,0%,100%,.5);
    margin: 0;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    transition: opacity .3s;
    /*background-color: rgba(0, 0, 0, 0.8);*/
    text-align: center;
    padding-top: 20%;
  }
</style>
